#include <stdio.h>
#define MAXLEN 19
int main()
{
    int n, s;
    int flag1, flag2 = 1;
    int z;
    char ch[MAXLEN] = {'\0'};
    char arr_mod[] = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
    int arr_sum[] = {
        7,
        9,
        10,
        5,
        8,
        4,
        2,
        1,
        6,
        3,
        7,
        9,
        10,
        5,
        8,
        4,
        2,
    };
    scanf("%d", &n);
    getchar();
    for (int i = 0; i < n; i++)
    {
        s = 0;
        flag1 = 1;
        for (int j = 0; j < 18; j++)
        {
            scanf("%c", &ch[j]);
            if (j < 17)
            {
                s += arr_sum[j] * (ch[j] - 48);
                if (ch[j] < 48 || ch[j] > 57)
                {
                    flag1 = 0;
                }
            }
        }
        while (getchar() != '\n')
        {
            ;
        }
        z = s % 11;
        if (flag1 == 0 || arr_mod[z] != ch[17])
        {
            printf("%s\n", ch);
            flag2 = 0;
        }
    }
    if (flag2 == 1)
    {
        printf("All passed");
    }
    return 0;
}